/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.arthurh.android.BdeInfo;

import android.view.View;
import android.widget.Toast;
import com.arthurh.android.BdeInfo.connection.*;
import android.view.Display;
import android.widget.TextView;
import android.widget.LinearLayout;
import android.app.Activity;

import android.content.res.Resources;
import android.os.Handler;
import android.os.Bundle;
import android.widget.ScrollView;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TabHost;
import android.widget.Toast;
import java.util.ArrayList;
import java.lang.Runnable;
/**
 *
 * @author arthur
 */
public class News extends Activity
{
    /** Called when the activity is first created. */
    private ScrollView scrollLayout;
    private LinearLayout layout ;
    private TextView textView;
    private int m_interval = 30000; // 5 seconds by default, can be changed later
    private Handler m_handler;


    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        
        super.onCreate(savedInstanceState);
        this.setTitle("BdeInfo - News");
        scrollLayout = new ScrollView(this);
        layout = new LinearLayout(this);
        scrollLayout.addView(layout);
        layout.setOrientation(LinearLayout.VERTICAL);
        textView = new TextView(this);
        layout.addView(textView);
        this.updateNews();
        

        setContentView(scrollLayout);
        m_handler = new Handler();
        this.startRepeatingTask();
    }
    Runnable m_statusChecker = new Runnable()
    {
         @Override 
         public void run() {
              updateNews();
              m_handler.postDelayed(m_statusChecker, m_interval);
         }
    };
    void startRepeatingTask()
    {
        m_statusChecker.run(); 
    }

    

    public void updateNews(){
        Connection conn = new Connection();

        ArrayList<Entry> news= conn.getNewsStream();
        
        String text = "";
        for(int i=0; i<news.size(); i++){
            text += news.get(i).toString()+"\n\n";  
        }
        textView.setText(text);
        
        
    }
    

    
}